package com.nf.health.app.healthstate.activity;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.healthstate.adapter.HealthStateAdapter;
import com.nf.health.app.models.HealthStateInfo;

import butterknife.Bind;
import butterknife.ButterKnife;

public class HealthStateActivity extends BaseActivity {

    private static final String FLAG_HEALTH_STATE = "healthState";
    @Bind(R.id.titlebar_title_tv)
    TextView titlebarTitleTv;
    @Bind(R.id.recyclerView)
    RecyclerView recyclerView;
    HealthStateAdapter healthStateAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_health_state);

        ButterKnife.bind(this);
        setUpView();

        provider.requestHealthStateDetail(FLAG_HEALTH_STATE);
    }

    @Override
    public void handleActionSuccess(String actionName, Object object) {
        if(FLAG_HEALTH_STATE.equals(actionName)){
            HealthStateInfo healthStateInfo = (HealthStateInfo)object;

            healthStateAdapter = new HealthStateAdapter(this, healthStateInfo);
            recyclerView.setAdapter(healthStateAdapter);
        }
    }

    private void setUpView() {
        titlebarTitleTv.setText(R.string.health_state);

        recyclerView.setHasFixedSize(true);
        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }
}
